﻿using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pay.Web.Areas.Admin.Controllers {
    /// <summary>
    /// 集市商品
    /// </summary>
    [RouteArea("admin")]
    [RoutePrefix("BazaarProduct")]
    public class BazaarProductController : AdminController {
        private ITokenBazaarProductService _iTokenBazaarProductService;
        private ICategoryService _iCategoryService;
        public BazaarProductController(ITokenBazaarProductService iTokenBazaarProductService, ICategoryService iCategoryService) {
            _iTokenBazaarProductService = iTokenBazaarProductService;
            _iCategoryService = iCategoryService;
        }
        /// <summary>
        /// 集市
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Gets(BazaarProductQuery query) {
            query.is_all = true;
            var result = _iTokenBazaarProductService.Gets(query);
            return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public JsonResult Get(long id) {
            var result = _iTokenBazaarProductService.GetProduct(id);
            return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 获取分类
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetCategory() {
            var result = _iCategoryService.GetTokenFirstDepthCatagory(1);
            return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 下架
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Down(long id) {
            var result = _iTokenBazaarProductService.Down(id);
            return Json(ResultToJson.Json(result ? "下架成功" : "下架失败"), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 推荐
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Recommend(long id, bool isRecommend) {
            var result = _iTokenBazaarProductService.Recommend(id, isRecommend);
            return Json(ResultToJson.Json(result ? "保存成功" : "保存失败"), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public JsonResult Audit(long id, int categoryId, int status, decimal price, string remark) {
            var result = _iTokenBazaarProductService.Audit(id, categoryId, status, price, remark);
            return Json(ResultToJson.Json(result ? "审核成功" : "审核失败", result), JsonRequestBehavior.AllowGet);
        }
    }
}